package web.servlet;

import domain.Account;
import domain.Order;
import service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class ListOrderServlet extends HttpServlet {

    private static final String LIST_ORDER= "/WEB-INF/jsp/order/listOrder.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session=req.getSession();
        Account account=(Account)session.getAttribute("loginAccount");
        List<Order> orderlist;
        OrderService orderService=new OrderService();
        orderlist=orderService.getOrderByUserId(account.getUsername());
        session.setAttribute("orderList",orderlist);
        req.getRequestDispatcher(LIST_ORDER).forward(req,resp);
    }
}
